package com.lagou.edu.service.impl;

import com.lagou.edu.service.SendService;
import com.lagou.edu.util.MailUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author bobcheng
 * @date 2020/7/6
 */
@Service
@Slf4j
public class SendServiceImpl implements SendService {

    private static final String CAPTCHA_CONTENT = "您的邮箱验证代码为: %s，10分钟内有效。请在网页中填写，完成验证。";
    private static final String CAPTCHA_SUBJECT = "验证您的电子邮件地址";

    @Autowired
    private MailUtil mailUtil;


//    @Override
    public boolean sendCaptcha(String email, String code) {
        try {
            String body = String.format(CAPTCHA_CONTENT, code);
            mailUtil.sendMail(email, CAPTCHA_SUBJECT, body);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}
